
*------------------------------------------------------------------------------*
* Government position weighted by share of portfolios
*
* Additional specs:
*	1. Excluding NONAs and parties with missing ideology
*	2. Fallback: 1st chamber median for expert governments
*
* Version:	2016-06-10
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*


* Exclude NONAs and parties with missing ideology
gen filterport = p110 if p103 == 1 & $ideology != .
by g101 g105, sort: egen newsumport = sum(filterport)
gen newpofport = (filterport / newsumport * 100)

* Weigh new p% of cabinet portfolios with ideology
gen zs1 = ($ideology * newpofport) / 100

* Aggregate
by g101 g105, sort: egen GOV_POS = sum(zs1)
save zs, replace


* Fill in GOV_POS with fallbacks
replace GOV_POS = median1st if newsumport == 0 & GOV_POS == 0


* Cleansing
replace GOV_POS = . if g106 == 9

lab var GOV_POS "Position of government"

sort g101 g105 p101

capture: drop zs* filterseat newsumseat newpofseat 
capture: erase zs.dta
capture: erase zs_median.dta
